import routes from './routes'
import { createRouter, createWebHashHistory } from 'vue-router'
import { UserCheck } from 'api/config'

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach(async (to, from, next) => {
  if (to.path === '/') {
    const bol = UserCheck()
    if (!bol) {
      next()
    } else {
      next('/home')
    }
  } else {
    const bol = UserCheck()

    if (!bol) {
      next('/')
    } else {
      next()
    }
    // next()
  }
})

export default router
